package com.shigu.test;

import com.opentae.data.mall.beans.MoCard;
import com.opentae.data.mall.examples.MoCardExample;
import com.opentae.data.mall.interfaces.MoCardMapper;
import com.shigu.mo.bo.requests.UpCreditCardRequest;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;

import javax.validation.ConstraintViolation;
import javax.validation.Validation;
import javax.validation.Validator;
import java.util.List;
import java.util.Set;

public class CardFlush extends BaseSpringTest{

    @Autowired
    MoCardMapper moCardMapper;

    @Test
    public void flush(){
        List<MoCard> cards=moCardMapper.selectByExample(new MoCardExample());
        String result="";
        for(MoCard mc:cards){
            UpCreditCardRequest request=new UpCreditCardRequest();
            request.setBankName("1");
            request.setCreditCard(mc.getBankNo());
            if(validateModel(request)==1){
                System.out.println(mc.getBankNo());

                result+= mc.getBankNo()+",";
            }
        }
        System.out.println(result);
    }

    public   static  int validateModel(Object obj) { //验证某一个对象
        Validator validator = Validation.buildDefaultValidatorFactory()
                .getValidator();
        Set<ConstraintViolation<Object>> constraintViolations = validator
                .validate(obj);//验证某个对象,，其实也可以只验证其中的某一个属性的
        return constraintViolations.size();
    }
}
